package com.jeff.question100;

public class MountainExplorer {

    public static int countPeaks(int[] map) {
        int peakCount = 0;
        
        // 处理边缘情况，即数组开头和结尾可能形成的山峰
        if (map.length > 1 && map[0] > map[1]) peakCount++;
        if (map.length > 1 && map[map.length - 1] > map[map.length - 2]) peakCount++;

        // 遍历数组内部，识别山峰
        for (int i = 1; i < map.length - 1; i++) {
            if (map[i] > map[i - 1] && map[i] > map[i + 1]) {
                peakCount++;
            }
        }
        
        return peakCount;
    }

    public static void main(String[] args) {
        int[] map = {0,1,2,4,3,1,0,0,1,2,3,1,2,1,0};
        System.out.println("山峰数量: " + countPeaks(map));
    }
}
